﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Referrer.aspx.cs" Inherits="CRMWeb.Pages.Admin.Referrer" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Referrer Lender</title>
</head>
<body>
    <table id="dgReferrer" title="Referrer" style="width: 600%; height: 370px; overflow-y: auto;" toolbar="#toolbarReferrer" pagination="true" data-options="pageSize:10,pageList: [10,20,30,50]" rownumbers="true" fitcolumns="true" singleselect="true">
        <thead>
            <tr>
                <th field="ReferrerID" width="100px" align="center">Referrer ID</th>
                <th field="Referrer" width="500px" align="center">Referrer</th>
            </tr>
        </thead>
    </table>
    <div id="toolbarReferrer">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="newReferrer()">New</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editReferrer()">Edit</a>
        <a id="lnkDelete" href="javascript:void(0)" class="easyui-linkbutton" onclick="openDelRefPopup()" plain="true" iconcls="icon-remove" title="Delete Client">Delete</a>
    </div>
    <div id="dlgReferrer" class="easyui-dialog" style="width: 350px; height: 220px; padding: 10px 20px"
        closed="true" buttons="#dlg-buttons">
        <div class="ftitle">Referrer Information</div>
        <form id="fmReferrer" method="post" novalidate>
            <div class="fitem">
                <label style="width: 130px;">Referrer:</label>
                <input id="txtReferrer" style="width: 292px;" class="easyui-validatebox" required="true" />
                <input id="hdnReferrerID" value="" style="display: none" />
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlgReferrer').dialog('close')" style="float: left">Cancel</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="saveReferrer()">Save</a>
    </div>

    <script type="text/javascript">

        var url;
        function newReferrer() {
            $('#dlgReferrer').dialog('open').dialog('setTitle', 'New Referrer');
            $('#fmReferrer').form('clear');
            $('#txtReferrer').val('');
            $('#hdnReferrerID').val('');
            url = '/WebServices/Referrer/ReferrerAdd';
        }

        function editReferrer() {
            var row = $('#dgReferrer').datagrid('getSelected');
            if (row) {
                $('#dlgReferrer').dialog('open').dialog('setTitle', 'Edit OutSource Lender');
                $('#fmReferrer').form('load', row);
                $('#txtReferrer').val(row.Referrer);
                $('#hdnReferrerID').val(row.ReferrerID);
                url = '/WebServices/Referrer/ReferrerAdd?ReferrerID=' + row.ReferrerID;
            }
        }
        //Resize datagrid:
        window.onresize = function () {
            $('#dgReferrer').datagrid('resize', {
                width: window.innerWidth - 165,
                height: window.innerHeight - 40
            });
        }
        function openDelRefPopup() {
            var row = $('#dgReferrer').datagrid('getSelected');
            if (row) {
                $('#headertext').html("Are you sure want to delete this Refere?");
                $('#dlgDelconfirm').dialog('open');
                $('#btnDelete').bind("click", function () {
                    deleteReferrer();
                });
            }
        }

        function deleteReferrer() {
            var row = $('#dgReferrer').datagrid('getSelected');
            if (row) {
                $.ajax({
                    url: '/WebServices/Referrer.ashx',
                    type: 'POST',
                    data: {
                        method: 'ReferrerDelete',
                        args: { ReferrerID: row.ReferrerID }
                    },
                    success: function (data) {
                        $('#dgReferrer').datagrid('reload');
                        $('#dlgDelconfirm').dialog('close');
                    }
                });
            }
        }
        function saveReferrer() {
            var strReferrer = $('#txtReferrer').val();
            var ReferrerID = $('#hdnReferrerID').val();

            if (ReferrerID != '') {
                if (strReferrer != '') {
                    $.ajax({
                        url: '/WebServices/Referrer.ashx',
                        type: 'POST',
                        data: {
                            method: 'ReferrerEdit',
                            args: { ReferrerID: ReferrerID, Referrer: strReferrer }
                        },
                        success: function (data) {
                            if (data == 1) {
                                $('#dlgReferrer').dialog('close');
                                $('#dgReferrer').datagrid('reload');
                            }
                            else {
                                alert('Referrer already exist');
                            }
                        }
                    });
                }
            }
            else {
                if (strReferrer != '') {
                    $.ajax({
                        url: '/WebServices/Referrer.ashx',
                        type: 'POST',
                        data: {
                            method: 'ReferrerAdd',
                            args: { Referrer: strReferrer }
                        },
                        success: function (data) {
                            if (data == 1) {
                                $('#dlgReferrer').dialog('close');
                                $('#dgReferrer').datagrid('reload');
                            }
                            else {
                                alert('Referrer already exist.');
                            }
                        }
                    });
                }
            }
        }

        $(document).ready(function () {
            $('#dgReferrer').datagrid({
                url: '/WebServices/Referrer.ashx?method=ReferrerSelect',
                onDblClickRow: function (index, rowdata) {
                    editReferrer();
                }
            });
        });

    </script>
</body>
</html>

